package com.linln.modules.points.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.modules.points.domain.Points;
import com.linln.modules.points.repository.PointsMapper;
import com.linln.modules.points.service.PointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.modules.points.service.impl
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.modules.points.service.impl
 * @Description: TODO
 * @date Date : 2020年12月11日 16:23
 */
@Service
public class PointsServiceImpl extends ServiceImpl<PointsMapper, Points> implements PointsService {

    @Autowired
    private PointsMapper pointsMapper;

    @Override
    public Map<String, Object> getPointsByType(Integer pageNum, Integer limit, long userId, Integer pointsType) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum + 1, limit);
        PageInfo<Points> pageInfo = new PageInfo<>(pointsMapper.getPointsByType(userId, pointsType));
        map.put("code", 200);
        map.put("data", pageInfo.getList());
        map.put("total", pageInfo.getTotal());
        return map;
    }

    @Override
    public boolean addPoints(Points points) {
        return this.save(points);
    }
}
